package com.javabean;


import java.sql.*;
import java.util.Date;

import com.model.DataBase;

public class DeleteDevice {
	boolean isdelete = false;
	Connection con = DataBase.getConnection();
	PreparedStatement pre;

	public boolean isdelete(long pid) {
		String sql = "update device set state=?  where did=?";
		try {
			pre = con.prepareStatement(sql);
			pre.setString(1, "no");
			pre.setLong(2, pid);
			pre.executeUpdate();
			isdelete = true;
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return isdelete;
	}
	/**
	 * userid的值为当前登录用户的id
	 * @param pid
	 * @param userid
	 * @param position
	 */
   public void delete_record(int pid,int userid){
	   String sql="insert into borrow_record (DeviceId,BorrowDate,BorrowerId,BorrowOrReturn) values(?,?,?,?) ";
	   try {
		pre=con.prepareStatement(sql);
		Date date=new Date();
		pre.setInt(1, pid);
		pre.setDate(2, new java.sql.Date(date.getTime()));
		pre.setInt(3, userid);
		pre.setString(4, "该设备被删除");
		pre.executeUpdate();
		
	} catch (SQLException e) {
		e.printStackTrace();
	}
   }
}
